import { Exclude, Expose, Transform, Type } from "class-transformer";
import { IsArray, IsNotEmpty, IsNumber, IsOptional, IsString, Length } from "class-validator";


class TestDto {

    @Expose()
    @Type(() => String) // 使用 Type 装饰器指定类型,可以进行类型转换，但是SerializeInterceptor拦截器的enableImplicitConversion要设置为true
    roles: string[];

    @Expose()
    @Type(() => Date)
    date: Date;
}

export class SigninUserDto {
    @IsString()
    @IsNotEmpty()
    @Length(6, 20, {
        message: '用户名长度必须在6到20之间',
    })
    @Expose()
    username: string;

    @IsString()
    @IsNotEmpty()
    @Length(6, 20, {
        message: ({ constraints }) => `密码长度必须在${constraints[0]}到${constraints[1]}之间`,
    })
    @Exclude()
    password: string;

    @IsArray()
    @IsOptional()
    /* @IsNumber({}, {
        each: true, // 每个数字都需要满足条件
    }) */
    // @Transform((value: any) => value.map((e: any) => parseInt(e))) // 将字符串数组转换为数字数组
    roles: number[];


    test: TestDto;
}